package com.shameit.goodqrinfomanager.ui.activity.actionlog;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chad.library.BR;
import com.shameit.goodqrinfomanager.AppViewModelFactory;
import com.shameit.goodqrinfomanager.BaseMVVMActivity;
import com.shameit.goodqrinfomanager.R;
import com.shameit.goodqrinfomanager.adapter.ActionAdapter;
import com.shameit.goodqrinfomanager.bean.enity.ActionLogBean;
import com.shameit.goodqrinfomanager.databinding.ActivityActionLogBinding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class ActionLogActivity extends BaseMVVMActivity<ActivityActionLogBinding, ActionLogViewModel> {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setToolBarBack(binding.toolbar);
    }

    @Override
    protected String setTitle() {
        return "操作日志";
    }

    @Override
    protected void initView() {
        binding.rvActions.setLayoutManager(new LinearLayoutManager(this));
        binding.rvActions.setAdapter(viewModel.actionAdapter = new ActionAdapter(R.layout.item_action_log));
//        View view = LayoutInflater.from(this).inflate(R.layout.header_action_log, null, false);
//        viewModel.actionAdapter.addHeaderView(view);
    }

    private final static String[] types = {"登录", "出库", "入库"};

    @Override
    protected void loadData() {
        ArrayList arrayList = new ArrayList();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
        for (int i = 0; i < 5; i++) {
            ActionLogBean actionLogBean = new ActionLogBean();
            actionLogBean.setOperator("00" + (i + 1));
            actionLogBean.setResult("成功");
            actionLogBean.setType(types[i % 3]);
            actionLogBean.setTime(simpleDateFormat.format(new Date()));
            arrayList.add(actionLogBean);
        }
        viewModel.actionAdapter.setNewInstance(arrayList);
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_action_log;
    }

    @Override
    public int initVariableId() {
        return BR.viewmodel;
    }

    @Override
    public ActionLogViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(ActionLogViewModel.class);
    }
}
